package com.nstc.sftpExchange.config;

import com.nstc.sftpExchange.config.httpClient.HttpClient;
import com.nstc.sftpExchange.config.httpClient.HttpClientProperties;
import com.nstc.sftpExchange.config.sftp.EnableFtpTemplates;
import com.nstc.sftpExchange.config.sftp.FtpTemplateRegistrarProcessor;
import com.nstc.sftpExchange.config.sftp.SftpConfigProperties;
import com.nstc.sftpExchange.config.sftp.SftpRoutingPool;
import com.nstc.sftpExchange.util.SpringBean;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableFtpTemplates
public class GlobalConfiguration {

    @Bean
    public SpringBean springBean(){
        return new SpringBean();
    }

    @Bean(name = "sftpRoutingPool")
    public SftpRoutingPool sftpRoutingPool(SftpConfigProperties sftpPoolProperties) throws Exception {
        return new SftpRoutingPool(sftpPoolProperties);
    }

    @Bean
    public FtpTemplateRegistrarProcessor ftpTemplateRegistrarProcessor(SftpConfigProperties sftpPoolProperties,
                                                                       SftpRoutingPool sftpRoutingPool,
                                                                       ConfigurableListableBeanFactory beanFactory) {
        return new FtpTemplateRegistrarProcessor(sftpPoolProperties, sftpRoutingPool, beanFactory);
    }

    @Bean
    public HttpClient httpClient(HttpClientProperties httpClientProperties) {
        return new HttpClient(httpClientProperties);
    }
}
